﻿using System.Linq;

namespace BitsOfStuff
{
    internal static class ShortShapeRecognition
    {
        private static int _shortSequence;

        public static int getShortSequence()
        {
            return _shortSequence;
        }

        public static bool isShortShape(MyPoint[] stroke)
        {
            if (stroke.Length < 15)
                return true;
            return false;
        }

        public static bool[] analyze(MyPoint[] stroke)
        {
            if (isDot(stroke))
            {
                _shortSequence = -2;
                return new bool[1]; // If its only dot
            }

            if (isLong(stroke))
            {
                _shortSequence = -3;
                return new bool[2];
            }
            _shortSequence = -4;
            return new bool[3];
        }

        private static bool isDot(MyPoint[] stroke)
        {
            MyPoint start = stroke.FirstOrDefault();
            for (int i = 1; i < stroke.Length; i++)
            {
                if (start.getDistanceToPoint(stroke[i]) > MyParameters.shortMinimalDotRadius)
                    return false;
            }
            return true;
        }

        private static bool isLong(MyPoint[] stroke)
        {
            var virtualLong = new MyVector();
            virtualLong.makeVector(stroke.FirstOrDefault(), stroke.LastOrDefault());
            for (int i = 1; i < stroke.Length - 1; i++)
            {
                if (virtualLong.distance(stroke[i]) > MyParameters.shortMinimalLongDistance)
                    return false;
            }
            return true;
        }
    }
}